Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TestTelegramConfirmedRequest #215

Merged
merged 4 commits into from
Aug 31, 2024

Conversation

cyb3r4nt
Copy link
Contributor

There were two different race conditions between logic in TestTelegramConfirmedRequest
and TelegramAPIMock.GetUpdatesFunc and TelegramAPIMock.SendFunc:

  • GetUpdatesFunc may start before token was fetched,
    then it produces empty telegramUpdate response, which causes assertions in SendFunc to fail.
  • When token becomes used and removed from wait queue after successful login completion,
    then GetUpdatesFunc may be still called and new telegram update is created for same token.
    This breaks telegram update processing logic,
    and SendFunc gets called with the error parameter, which also breaks assertions.

Some of these failures were observed here: https://github.com/go-pkgz/auth/actions/runs/10632296696/job/29474964583?pr=214#step:6:778

=== RUN   TestTelegramUnconfirmedRequest
--- PASS: TestTelegramUnconfirmedRequest (0.12s)
=== RUN   TestTelegramConfirmedRequest
--- PASS: TestTelegramConfirmedRequest (0.03s)
=== RUN   TestTelegramLogout
panic: Fail in goroutine after TestTelegramConfirmedRequest has completed

goroutine 394 [running]:
testing.(*common).Fail(0xc000083ba0)
	/opt/hostedtoolcache/go/1.21.13/x64/src/testing/testing.go:952 +0x1b4
testing.(*common).Errorf(0xc000083ba0, {0xf4a4ad, 0x3}, {0xc000419ca0, 0x1, 0x1})
	/opt/hostedtoolcache/go/1.21.13/x64/src/testing/testing.go:1069 +0xaf
github.com/stretchr/testify/assert.Fail({0x11d5da0, 0xc000083ba0}, {0xc0000c6070, 0x6d}, {0x0, 0x0, 0x0})
	/home/runner/go/pkg/mod/github.com/stretchr/testify@v1.9.0/assert/assertions.go:363 +0x436
github.com/stretchr/testify/assert.Equal({0x11d5da0, 0xc000083ba0}, {0xe6df40?, 0x11d3460}, {0xe6df40?, 0xc000419b60?}, {0x0, 0x0, 0x0})
	/home/runner/go/pkg/mod/github.com/stretchr/testify@v1.9.0/assert/assertions.go:466 +0x3d8
github.com/go-pkgz/auth/v2/provider.TestTelegramConfirmedRequest.func3({0x11dbb50, 0xc000458eb0}, 0x1?, {0xf4aef0, 0x5})
	/home/runner/work/auth/auth/v2/provider/telegram_test.go:126 +0x116
github.com/go-pkgz/auth/v2/provider.(*TelegramAPIMock).Send(0xc0002c08c0, {0x11dbb50, 0xc000458eb0}, 0x12aa0131, {0xf4aef0, 0x5})
	/home/runner/work/auth/auth/v2/provider/telegram_moq_test.go:204 +0x279
github.com/go-pkgz/auth/v2/provider.(*TelegramHandler).processUpdates(0xc000272f20, {0x11dbb50, 0xc000458eb0}, 0xc0001b3740)
	/home/runner/work/auth/auth/v2/provider/telegram.go:173 +0xb7d
github.com/go-pkgz/auth/v2/provider.(*TelegramHandler).Run(0xc000272f20, {0x11dbb50, 0xc000458eb0})
	/home/runner/work/auth/auth/v2/provider/telegram.go:94 +0x5d2
github.com/go-pkgz/auth/v2/provider.setupHandler.func2()
	/home/runner/work/auth/auth/v2/provider/telegram_test.go:398 +0x66
created by github.com/go-pkgz/auth/v2/provider.setupHandler in goroutine 393
	/home/runner/work/auth/auth/v2/provider/telegram_test.go:397 +0x5eb
FAIL	github.com/go-pkgz/auth/v2/provider	5.645s
=== RUN   TestEmailSend
    email_test.go:15: 
--- SKIP: TestEmailSend (0.00s)
=== RUN   TestEmail_New
--- PASS: TestEmail_New (0.00s)
=== RUN   TestEmail_SendFailed

Now it is possible to have a configuration,
where only one single dev provider is enabled.

Providers were not registered into Service.authMiddleware.Provicers slice
in the Service.AddDevProvider() and Service.AddAppleProvider() methods before.
There were two different race conditions between logic in TestTelegramConfirmedRequest
and TelegramAPIMock.GetUpdatesFunc and TelegramAPIMock.SendFunc:
* GetUpdatesFunc may start before token was fetched,
then it produces empty telegramUpdate response, which causes assertions in SendFunc to fail.
* When token becomes used and removed from wait queue after successful login completion,
then GetUpdatesFunc may be still called and new telegram update is created for same token.
This breaks telegram update processing logic,
and SendFunc gets called with the error parameter, which also breaks assertions.
@umputun umputun merged commit 34ded9b into go-pkgz:master Aug 31, 2024
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants